<!DOCTYPE html>
<html lang="ch">
<head>
    <meta charset="UTF-8">
    <title>JPetStore后台管理-登陆</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/login.css" media="all"/>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script type="text/javascript">
        function toPhoneLogin(){
            $.ajax({
                url:"/toPhoneLogin",
                success:function (data){
                    alert(data);
                    $(".accountLogin").html(data);
                }
            })
        }
        function toAccountLogin(){
            $.ajax({
                url:"/toAccountLogin",
                success:function (data){
                    alert(data);
                    $(".phoneLogin").html(data);
                }
            })
        }
        function getVerifyCode() {
            var fphoneNumber = $("#fphoneNumber");
            if($.trim(fphoneNumber.val())==""){
                alert("电话不能为空");
                fphoneNumber.val("");
                fphoneNumber.focus();
            }else{
                console.log(fphoneNumber.val())
                $.ajax({
                    url: "/sendSms",
                    async : true,
                    type: "POST",
                    dataType: "json",
                    data: {"phoneNumber":fphoneNumber.val()},
                    success: function (data) {
                        if(data == 'fail'){
                            alert("发送验证码失败");
                        }else{
                            alert("发送验证码成功");
                        }
                    }
                });
            }
        }
        //输入验证码后提交到后台是否输入合法
        function dologin() {
            var fverifyCode = $("#fverifyCode");
            if($.trim(fverifyCode.val())==""){
                alert("验证码不能为空");
                fverifyCode.val("");
                fverifyCode.focus();
            }else{
                var data={
                    "verifyCode":fverifyCode.val()
                };
                var verifyCode =fverifyCode.val();
                $.ajax({
                    type: "POST",
                    url: "/doLogin?verifyCode="+verifyCode,
                    contentType: "application/json",
                    dataType: "JSON",
                    // data: JSON.stringify(data),
                    success: function (obj) {
                        console.log(obj);
                        if(obj.data=='登录成功'){
                            window.location.href="/index";
                        }else{
                            alert(obj.data);
                            fverifyCode.val("");
                        }
                    },
                    error: function (obj) {
                        console.log(obj);
                        layer.msg("登录失败!", {time:1000, icon:5, shift:6});
                    }
                })
            }
        }
    </script>
</head>
<body>
<div class="main-body">
    <div class="login-main">
        <div class="login-top">
            <span>JpetStore后台登录</span>
            <span class="bg1"></span>
            <span class="bg2"></span>
        </div>
        <form class="layui-form login-bottom" action="/login" method="post">
            <div class="center">
                <div class="layui-font-red" th:if="${loginMsg!=null}">
                    <span th:text="${loginMsg}"></span>
                </div>
                <div class="accountLogin" th:frament="accountLogin">
                    <div class="item">
                        <span class="icon icon-2"></span>
                        <input type="text" name="username"   placeholder="请输入登录账号" maxlength="24"/>
                    </div>

                    <div class="item">
                        <span class="icon icon-3"></span>
                        <input type="password" name="password"  placeholder="请输入密码" maxlength="20">
                        <span class="bind-password icon icon-4"></span>
                    </div>

                    <div class="layui-form-item" style="text-align:center; width:100%;height:100%;margin:0px;" >
                        <a class="underline" href="https://gitee.com/oauth/authorize?response_type=code&client_id=27b50a9ae74a7c49e7cb3faa74783eda27cf726abccaf1cf932d5227fe37a1af&redirect_uri=http://localhost:8080/index">
                            Gitee登录
                        </a>
                        /
                        <label onclick="toPhoneLogin()" class="underline">
                            手机短信登录
                        </label>
                    </div>
                    <div class="layui-form-item" style="text-align:center; width:100%;height:100%;margin:0px;">
                        <button class="login-btn" type="submit">
                            立即登录
                        </button>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>
</body>
</html>